package com.dycx.payment.converter;

import java.time.LocalDateTime;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.payment.entity.PaymentOrderDO;
import com.dycx.payment.vo.PaymentOrderVO;
import com.dycx.payment.dto.PaymentOrderDTO;

/**
 * 文章关键字(PaymentOrder)实体转换类
 *
 * @author wuzongbin
 * @since 2024-01-16 09:57:09
 */


@Data
public class PaymentOrderConverter implements Serializable {
    public static PaymentOrderDO dtoToEntity(PaymentOrderDTO dto) {
        if (dto == null) return null;
        PaymentOrderDO entity = BeanUtil.toBean(dto, PaymentOrderDO.class);
        return entity;
    }

    public static PaymentOrderVO entityToVo(PaymentOrderDO entity) {
        if (entity == null) return null;
        PaymentOrderVO vo = BeanUtil.toBean(entity, PaymentOrderVO.class);

        return vo;
    }

    public static List<PaymentOrderVO> entityToVoList(List<PaymentOrderDO> entityList) {
        List<PaymentOrderVO> voList = new ArrayList<>();
        for (PaymentOrderDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<PaymentOrderVO> entityToVoPage(Page<PaymentOrderDO> page) {

        List<PaymentOrderVO> newRecords = new ArrayList<>();

        List<PaymentOrderDO> records = page.getRecords();
        for (PaymentOrderDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<PaymentOrderVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
